package controller;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import dao.UserDAO;
import entity.User;

@Controller
public class UserController {
	
/*	
	
	@RequestMapping("/check1.do")
	public ModelAndView checl1(HttpSession session,User user) {
		String path="login.jsp";
		if("wang".equals(user.getName())) {
			session.setAttribute("name", user.getName());
			path="welcome.jsp";
		}
//		ModelAndView mav=new ModelAndView(path);	容器传参数
//		mav.addObject("name", user.getName());	容器内得到的
		
		ModelAndView mav=new ModelAndView(new RedirectView(path));	//外部跳转
		return mav;
	}
	
*/
	
	UserDAO userDAO;
	
	public UserDAO getUserdao() {
		return userDAO;
	}

	@Resource
	public void setUserdao(UserDAO userdao) {
		this.userDAO = userdao;
	}

	@RequestMapping("/check.do")
	public String check(HttpSession session,User user) throws IOException {
		String path="login";
		if(userDAO.isValid(user)) {
			session.setAttribute("name", user.getName());
			path="welcome";
		}
//		return path;	容器跳转
		return path;	//外部跳转
	}
	
	
}
